package IA.GA.editorial;

import org.jgap.Chromosome;
import org.jgap.Configuration;
import org.jgap.DefaultFitnessEvaluator;
import org.jgap.DeltaFitnessEvaluator;
import org.jgap.Gene;
import org.jgap.IBreeder;
import org.jgap.InvalidConfigurationException;
import org.jgap.Population;
import org.jgap.distr.Breeder;
import org.jgap.distr.IPopulationMerger;
import org.jgap.event.EventManager;
import org.jgap.impl.FittestPopulationMerger;
import org.jgap.impl.GaussianRandomGenerator;
import org.jgap.impl.IntegerGene;
import org.jgap.impl.StockRandomGenerator;

import IA.GA.editorial.domain.BookFitnes;
import IA.GA.editorial.domain.SuperGeneTraductor;
import IA.GA.util.CustomRandom;

public abstract class AbstractConfigFactory {	
	
	public Configuration getConfig(Integer poblacionSize) throws InvalidConfigurationException{
	Configuration conf = new Configuration();		
	conf.setFitnessEvaluator(new DefaultFitnessEvaluator());
//	conf.setFitnessEvaluator(new DeltaFitnessEvaluator());
//	conf.setPreservFittestIndividual(true);
	conf.setEventManager(new EventManager());
//	conf.setRandomGenerator(new CustomRandom());
	conf.setRandomGenerator(new StockRandomGenerator());
	conf.setPopulationSize(poblacionSize);
	conf.setKeepPopulationSizeConstant(false);	
//	Comportamiento raro ..
//	conf.setSelectFromPrevGen(0.5);
	setParameters(conf);

	Gene[] traductores = new Gene[3];
	traductores[0] =  new SuperGeneTraductor(conf,getTraductor(conf));
	traductores[1] = new SuperGeneTraductor(conf,getTraductor(conf));
	traductores[2] = new SuperGeneTraductor(conf,getTraductor(conf));

	Chromosome prototipeChromosome = new Chromosome(conf, traductores);	
	conf.setSampleChromosome(prototipeChromosome);
	
		return conf;
	}
	
	public abstract void setParameters(Configuration conf) throws InvalidConfigurationException;

	private Gene[] getTraductor(Configuration conf)
			throws InvalidConfigurationException {
		Gene[] sampleGenes = new Gene[4];

		 sampleGenes[0] = new IntegerGene(conf, 0, 2); //Tipo de libro
		 sampleGenes[1] = new IntegerGene(conf, 0, 2); //Idiomas
		 sampleGenes[2] = new IntegerGene(conf, 0, 2); //Longitud libro
		 sampleGenes[3] = new IntegerGene(conf, 0, 1); //Cantidad de paginas
		return sampleGenes;
	}
	
}
